#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2021/12/18 12:41
    Desc  :
--------------------------------------
"""
from django.db import models
from apps import AbstractBaseModel
from common.enums.person_enums import MenuTypeEnum, MenuStatusEnum


class Menu(AbstractBaseModel):
    name = models.CharField(max_length = 255, help_text = '菜单标题')
    code = models.IntegerField(help_text = '菜单code')
    type = models.IntegerField(help_text = '权限类型: 101 一级菜单，102 二级菜单，103 三级菜单, 104 按钮', default = MenuTypeEnum.FIRST_MENU.key)
    status = models.IntegerField(help_text = '状态: 101 启用 102 停用', default = MenuStatusEnum.ENABLE.key)
    parentCode = models.ForeignKey('self', on_delete = models.SET_NULL, null = True, blank = True,
                                   help_text = '父级菜单code',
                                   related_name = 'children')

    class Meta:
        verbose_name = '权限管理'
        verbose_name_plural = verbose_name
        unique_together = ['code', 'deleted']
        db_table = 'tMenu'
        ordering = ['code', '-createTime']


class MenuAction(AbstractBaseModel):
    action = models.CharField(max_length = 255, help_text = '操作')
    describe = models.CharField(max_length = 255, help_text = '操作描述')
    defaultCheck = models.BooleanField(default = False, help_text = '是否默认校验')
    menuId = models.IntegerField(help_text = '所属菜单')

    class Meta:
        verbose_name = '菜单操作管理'
        verbose_name_plural = verbose_name
        unique_together = ['menuId', 'action', 'deleted', 'createTime']
        db_table = 'tMenuAction'
        ordering = ['-createTime']
